﻿using System;
using System.Runtime.Remoting.Channels.Ipc;
using System.Windows.Forms;
using RemotingGuidance;
using TestConsoleServer;

namespace TestWindowsFormsClient
{
    public partial class MainForm : Form
    {
        private TestServerGuidance f_Guidance;

        public MainForm()
        {
            InitializeComponent();
            Uri_TextBox.Text = string.Format(@"{0}://{1}:{2}/{3}",
                "ipc", "localhost", 9090, typeof(TestServerGuidance).FullName);
        }

        private void Connect_Button_Click(object sender, EventArgs e)
        {
            var channel = new IpcChannel();
            Guidance.RegisterClient<TestServerGuidance>(channel, false, Uri_TextBox.Text);
            f_Guidance = Guidance.Create<TestServerGuidance>(Uri_TextBox.Text);
        }

        private void Write_Button_Click(object sender, EventArgs e) { f_Guidance.WriteToConsol(Text_TextBox.Text); }

        private void WriteLN_Button_Click(object sender, EventArgs e) { f_Guidance.WriteToConsolLN(Text_TextBox.Text); }

        private void CloseServer_Button_Click(object sender, EventArgs e) { f_Guidance.CloseServer(); }
    }
}
